﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VirtualBank
{
    public partial class OptionForm : Form
    {       
        Account account=new Account(10000,"周","123456",13000.6);
       

        public OptionForm()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }

        private void withdrawButton_Click(object sender, EventArgs e)
        {
            double amount;
           
            try
            {   //判断用户输入金额是否合法
                bool success=double.TryParse(textBox1.Text, out amount );
                if (!success)
                {
                    throw new Exception("不合法的金额输入");
                }
                account.withdraw(amount);
                MessageBox.Show("您已成功取款：" + amount + "元");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void saveButton_Click(object sender, EventArgs e)
        {

            double amount;

            try
            {   //判断用户输入金额是否合法
                bool success = double.TryParse(textBox1.Text, out amount);
                if (!success)
                {
                    throw new Exception("不合法的金额输入");
                }
                account.Deposit(amount);
                MessageBox.Show("您已成功取款：" + amount + "元");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("您的余额为" + account.Balance);
        }
    }
}
